package cn.tedu.kcircle.passport.adapter.controller;

import cn.tedu.kcircle.common.po.CurrentPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "test",produces = "application/json;charset=utf-8")
@Tag(name="测试登录")
public class TestController {
    @GetMapping("/authenticated")
    @Operation(summary = "基于Security框架的认证")
    public String checkAuthentication(){
        return "已经通过Spring Security框架的认证！";
    }

    @GetMapping("/principal")
    @Operation(summary = "获取当事人信息")
    public String checkAuthentication(@AuthenticationPrincipal CurrentPrincipal login){
        return "user-id:"+login.getUserId();
    }

    @GetMapping("authorize")
    @PreAuthorize("hasAuthority('/admin')")
    @Operation(summary = "基于Security框架的授权")
    public String preAuthorize(){
        return "已经通过Security框架的授权";
    }

}
